package com.atguigu2.DBSConnectionPool;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.dbcp.BasicDataSourceFactory;
import org.junit.Test;


public class DBCPTest {
	private static DataSource source;
	static
	{
		try {
			FileInputStream is = new FileInputStream(new File("src//dbcp.properties"));
			Properties pros = new Properties();
			pros.load(is);
			source = BasicDataSourceFactory.createDataSource(pros);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Test
	public static Connection getConnection() throws Exception
	{
		Connection conn = source.getConnection();
//		System.out.println(conn);
//		DataSource source = BasicDataSourceFactory.createDataSource(pros);
//		Connection conn = (Connection) source.getConnection();
		return conn;
	}
	public static void main(String[] args) throws Exception {
		Connection conn = getConnection();
		System.out.println(conn);
	}
}
